<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <canvas id="c1" width="600" height="600"></canvas>
  <script>
    const c1 = document.getElementById('c1')
    const cvsCtx = c1.getContext('2d')

    let index = 0;
    function render() {
      cvsCtx.clearRect(0, 0, 600, 400);
      index += 0.01;
      if(index > 1){
        index = 0
      }
      let linearGradient = cvsCtx.createLinearGradient(100, 200, 400, 500);
      linearGradient.addColorStop(0, "red");
      linearGradient.addColorStop(index, "#ffcccc");
      linearGradient.addColorStop(1, "blue");
      cvsCtx.fillStyle = linearGradient;
      cvsCtx.fillRect(100, 200, 300, 300);
      requestAnimationFrame(render)
    }
    requestAnimationFrame(render)
    
  </script>
</body>
</html>